import { routerReset } from '@/router'

const state = {
  ready: false,
  menuList: [],
  roleList: [],
  dictMap: {}
}

const getters = {
  isReady (state) {
    return state.ready
  },
  getMenuList (state) {
    return state.menuList
  },
  getDictMap (state) {
    return state.dictMap
  },
  getDict (state) {
    return (dictName) => {
      return state.dictMap[dictName]
    }
  }
}

const mutations = {
  ready (state) {
    state.ready = true
  },
  reset (state) {
    state.ready = false
    state.menuList.length = 0
    state.roleList.length = 0
    state.dictMap = {}
    routerReset()
  },
  insertMenu (state, menu) {
    state.menuList.push(menu)
  },
  setMenuList (state, menuList) {
    state.menuList = menuList
  },
  setDictMap (state, dictMap) {
    state.dictMap = dictMap
  }
}

const actions = {
  ready ({ commit }) {
    commit('ready')
  },
  reset ({ commit }) {
    commit('reset')
  },
  insertMenu ({ commit }, menu) {
    commit('insertMenu', menu)
  }
}

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
}
